define("footballblog/FootballblogApiClient", 
		["dojo/_base/declare", "dojo/request", "dojo/domReady!"], 
		function (declare, request) {

		return declare(null,{
		
		apiPath: "/footballblog/api/",
			
		articleResourceName: "articles",
		
		authorResourceName: "authors",
		
		userResourceName: "users",
		
		ratingResourceName: "ratings",
		
		commentResourceName: "comments",
		
		isSync: false,
		
		timeout: 10000,
		
		handleAs: "json",

		getArticlesforAuthor: function(authorType, authorExternalId, callback){
			request.get(this.apiPath + this.authorResourceName + "/" + authorType + "/" + authorExternalId + "/" + this.articleResourceName,{

				sync: this.isSync,
				
				timeout: this.timeout,				
				
				handleAs: this.handleAs,				
				
				data: {
					authorType: authorType,
					authorExternalId: authorExternalId
				}
			}).then(function(response){
				console.log("ther server returned: " + response);
				//var article = JSON.parse(response);
				//var authorId = response.authorId;
				//var articleTitle = response.articleTitle;
				//var articleDate = response.createdOn;
				//var articleContent = response.articleText;
				callback(response);
			});
			
		},
		
		deleteArticle: function(articleId, callback){
			request.del(this.apiPath + this.articleResourceName + "/" + articleId, {

				sync: this.isSync,
				
				timeout: this.timeout,				
				
				handleAs: this.handleAs,				
				
				data: {
					articleId: articleId,
				}
			}).then(function(response){
				console.log("ther server returned: " + response);
				callback();
			});			
		},
		
		putArticle: function(articleId, articleTitle, articleText, callback){
			request.put(this.apiPath + this.articleResourceName + "/" + articleId, {

				sync: this.isSync,
				
				timeout: this.timeout,				
				
				handleAs: this.handleAs,				
				
				data: {
					articleTitle: articleTitle,
					articleText: articleText
				}
				
			}).then(function(response){
				console.log("ther server returned: " + response);
				callback();
			});
			

		},
		
		getArticle: function(articleId, callback){
			request.get(this.apiPath + this.articleResourceName + "/" + articleId, {

				sync: this.isSync,
				
				timeout: this.timeout,				
				
				handleAs: this.handleAs,				
				
				data: {
					articleId: articleId,
				}
			}).then(function(response){
				console.log("ther server returned: " + response);
				//var article = JSON.parse(response);
				//var authorId = response.authorId;
				//var articleTitle = response.articleTitle;
				//var articleDate = response.createdOn;
				//var articleContent = response.articleText;
				callback(response);
			});
		},	

		postArticle: function(authorId, articleTitle, articleContent, callback){
						
			request.post(this.apiPath + this.articleResourceName, {

				sync: this.isSync,
				
				timeout: this.timeout,				
				
				handleAs: this.handleAs,				
				
				data: {
					authorId: authorId,
					articleTitle: articleTitle,
					articleContent: articleContent
				}
				
			}).then(function(response){
				console.log("ther server returned: " + response);
				var articleId = response.articleId; 
				console.log("article id: " + articleId);
				callback(articleId);
			});
			
		},	
		postArticleRating: function(articleId, articleRating, callback){
			request.post(this.apiPath + this.articleResourceName + "/" + articleId + "/" + this.ratingResourceName, {

				sync: this.isSync,
				
				timeout: this.timeout,				
				
				handleAs: this.handleAs,				
				
				data: {
					articleRating: articleRating
				}
				
			}).then(function(response){
				console.log("ther server returned: " + response);
				callback(response);
			});			
		},
		
		postUser: function(userType, userExternalId, userName, userScreenName, userPicUrl, userBigPicUrl, userMiniPicUrl, callback){
			
			request.post(this.apiPath + this.userResourceName, {

				sync: this.isSync,

				timeout: this.timeout,				
				
				handleAs: this.handleAs,				

				data: {
					userType: userType, 
					userExternalId: userExternalId,
					userName: userName,
					userScreenName: userScreenName,
					userPicUrl: userPicUrl,
					userBigPicUrl: userBigPicUrl,
					userMiniPicUrl: userMiniPicUrl,
				}
			
			}).then(function(response){
				console.log("ther server returned: " + response);
				var userId = response.userId;
				console.log("user id: " + userId);
				callback(userId);
			});
						
		},
		postComment: function(articleId, userId, commentText, callback){
			request.post(this.apiPath + this.commentResourceName, {

				sync: this.isSync,

				timeout: this.timeout,				
				
				handleAs: this.handleAs,				

				data: {
					articleId: articleId, 
					userId: userId,
					commentText: commentText
				}
			
			}).then(function(response){
				console.log("ther server returned: " + response);
				callback(response);
			});
			
		}, 
		postAuthor: function(authorType, authorExternalId, authorName, authorScreenName, authorPicUrl, authorBigPicUrl, authorMiniPicUrl, callback){
			
			request.post(this.apiPath + this.authorResourceName, {

				sync: this.isSync,

				timeout: this.timeout,				
				
				handleAs: this.handleAs,				

				data: {
					authorType: authorType, 
					authorExternalId: authorExternalId,
					authorName: authorName,
					authorScreenName: authorScreenName,
					authorPicUrl: authorPicUrl,
					authorBigPicUrl: authorBigPicUrl,
					authorMiniPicUrl: authorMiniPicUrl,
				}
			
			}).then(function(response){
				console.log("ther server returned: " + response);
				var authorId = response.authorId;
				console.log("author id: " + authorId);
				callback(authorId);
			});
			
		}
	});	
});
